package com.jinzhi.jzweb.controller;


import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import cn.hutool.core.date.DateTime;
import com.google.gson.JsonObject;
import com.jinzhi.common.utils.StringUtil;
import com.jinzhi.jzapi.utils.HttpClientUtil;
import com.jinzhi.jzweb.domain.ExamUserRegistrationDO;
import com.jinzhi.jzweb.domain.TrainStudentInfoDO;
import com.jinzhi.jzweb.pojo.ExamUserRegistrationExportVo;
import com.jinzhi.jzweb.pojo.TrainStudentInfoExportVo;
import com.jinzhi.jzweb.service.ExamUserRegistrationService;
import com.jinzhi.jzweb.utils.EasyPoiUtil;
import com.jinzhi.sys.domain.UserDO;
import com.jinzhi.sys.domain.UserDetailDO;
import com.jinzhi.sys.service.UserService;
import lombok.val;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.ExamRegistrationDO;
import com.jinzhi.jzweb.service.ExamRegistrationService;
import com.jinzhi.common.utils.Result;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * <pre>
 *
 * </pre>
 * <small> 2023-03-30 15:35:16 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/examRegistration")
public class ExamRegistrationController extends BaseController {
	@Autowired
	private UserService userService;
	@Autowired
	private ExamRegistrationService examRegistrationService;
	@Autowired
	private ExamUserRegistrationService examUserRegistrationService;

	@GetMapping()
	@RequiresPermissions("jzweb:examRegistration:examRegistration")
	String ExamRegistration(){
		return "jzweb/examRegistration/examRegistration";
	}

	/**
	 *
	 * @description: 查询考试报名相关信息
	 * @author: YangQiWu
	 * @date: 2023/3/31 9:34
	 * @param: [examRegistrationDO]
	 * @return: com.jinzhi.common.utils.Result<com.baomidou.mybatisplus.plugins.Page<com.jinzhi.jzweb.domain.ExamRegistrationDO>>
	 **/
	@Log("查询考试报名相关信息")
	@ResponseBody
	@GetMapping("/listExamRegistration")
	@RequiresPermissions("jzweb:examRegistration:examRegistration")
	public Result<Page<ExamRegistrationDO>> listExamRegistration(ExamRegistrationDO examRegistrationDO){
		Wrapper<ExamRegistrationDO> wrapper = new EntityWrapper<ExamRegistrationDO>().orderBy("id", false);
		if (StringUtil.notEmpty(examRegistrationDO.getExamType())) {
			wrapper.eq("exam_type", examRegistrationDO.getExamType());
		}
		if (StringUtil.notEmpty(examRegistrationDO.getNoticeTitle())) {
			wrapper.like("notice_title", examRegistrationDO.getNoticeTitle());
		}
		wrapper.orderBy("publish_date",false);

		// 查询列表数据
		Page<ExamRegistrationDO> page = examRegistrationService.selectPage(getPage(ExamRegistrationDO.class), wrapper);
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
			ExamRegistrationDO obj = (ExamRegistrationDO) page.getRecords().get(i);
			if (obj.getExamType().equals("0")){
				obj.setExamType("1+X幼儿照护职业技能等级证书师资及考评员");
			}
			if (obj.getExamType().equals("1")){
				obj.setExamType("1+X幼儿照护职业技能等级证书高级师资及考评员");
			}
			if (obj.getExamType().equals("2")){
				obj.setExamType("1+X幼儿照护职业技能等级证书考评员到期复审换证");
			}
			if (obj.getExamType().equals("3")){
				obj.setExamType("1+X产后恢复职业技能等级证书师资及考评员");
			}
			if (obj.getExamType().equals("4")){
				obj.setExamType("1+X幼儿照护、产后恢复职业技能等级证书考务技术与督导员");
			}
			if (obj.getExamType().equals("5")){
				obj.setExamType("高职护理——江西国培");
			}
			if (obj.getExamType().equals("6")){
				obj.setExamType("中职幼儿保育——江西国培");
			}
			if (obj.getExamType().equals("7")){
				obj.setExamType("教学能力竞赛研修班");
			}
			if (obj.getExamType().equals("8")){
				obj.setExamType("金砖大赛 - 第二届婴幼儿照护训练营");
			}
			if (obj.getExamType().equals("9")){
				obj.setExamType("金砖大赛-首届产后恢复训练营");
			}
			if (obj.getExamType().equals("10")){
				obj.setExamType("2024年国培省培班");
			}
			if (obj.getExamType().equals("11")){
				obj.setExamType("会议");
			}
			if (obj.getExamType().equals("12")){
				obj.setExamType("1+X幼儿照护、产后恢复职业技能等级证书考务技术员与督导员到期复审换证");
			}
			if (obj.getExamType().equals("13")){
				obj.setExamType("1+X产后恢复职业技能等级证书考评员到期复审换证");
			}
			if (obj.getExamType().equals("14")){
				obj.setExamType("金砖大赛-第二届产后恢复训练营");
			}
			if (obj.getExamType().equals("15")){
				obj.setExamType("金砖大赛-第三届婴幼儿照护训练营");
			}
			if (obj.getExamType().equals("16")){
				obj.setExamType("金砖大赛-首届老年人能力评估训练营");
			}

			UserDO userDO = userService.selectById(obj.getUserId());
			obj.setUserName(userService.selectById(obj.getUserId()).getUsername());
			list.add(obj);
		}
		page.setRecords(list);
		return Result.ok(page);
	}

	/**
	 *
	 * @description: 培训信息详情
	 * @author: YangQiWu
	 * @date: 2023/3/31 11:01
	 * @param: [id, model]
	 * @return: java.lang.String
	 **/
	@Log("培训详情页面")
	@GetMapping("/infoExamRegistration1/{id}")
	String infoExamRegistration1(@PathVariable("id") Long id, Model model) {
		ExamRegistrationDO examRegistrationDO = examRegistrationService.selectById(id);
		if (examRegistrationDO.getExamType().equals("0")){
			examRegistrationDO.setExamType("1+X幼儿照护职业技能等级证书师资及考评员");
		}
		if (examRegistrationDO.getExamType().equals("1")){
			examRegistrationDO.setExamType("1+X幼儿照护职业技能等级证书高级师资及考评员");
		}
		if (examRegistrationDO.getExamType().equals("2")){
			examRegistrationDO.setExamType("1+X幼儿照护职业技能等级证书考评员到期复审换证");
		}
		if (examRegistrationDO.getExamType().equals("3")){
			examRegistrationDO.setExamType("1+X产后恢复职业技能等级证书师资及考评员");
		}
		if (examRegistrationDO.getExamType().equals("4")){
			examRegistrationDO.setExamType("1+X幼儿照护、产后恢复职业技能等级证书考务技术与督导员");
		}
		if (examRegistrationDO.getExamType().equals("5")){
			examRegistrationDO.setExamType("高职护理——江西国培");
		}
		if (examRegistrationDO.getExamType().equals("6")){
			examRegistrationDO.setExamType("中职幼儿保育——江西国培");
		}
		if (examRegistrationDO.getExamType().equals("7")){
			examRegistrationDO.setExamType("教学能力竞赛研修班");
		}
		if (examRegistrationDO.getExamType().equals("8")){
			examRegistrationDO.setExamType("金砖大赛 - 第二届婴幼儿照护训练营");
		}
		if (examRegistrationDO.getExamType().equals("9")){
			examRegistrationDO.setExamType("金砖大赛-首届产后恢复训练营");
		}
		if (examRegistrationDO.getExamType().equals("10")){
			examRegistrationDO.setExamType("2024年国培省培班");
		}
		if (examRegistrationDO.getExamType().equals("11")){
			examRegistrationDO.setExamType("会议");
		}
		if (examRegistrationDO.getExamType().equals("12")){
			examRegistrationDO.setExamType("1+X幼儿照护、产后恢复职业技能等级证书考务技术员与督导员到期复审换证");
		}
		if (examRegistrationDO.getExamType().equals("13")){
			examRegistrationDO.setExamType("1+X产后恢复职业技能等级证书考评员到期复审换证");
		}
		if (examRegistrationDO.getExamType().equals("14")){
			examRegistrationDO.setExamType("金砖大赛-第二届产后恢复训练");
		}
		if (examRegistrationDO.getExamType().equals("15")){
			examRegistrationDO.setExamType("金砖大赛-第三届婴幼儿照护训练营");
		}
		if (examRegistrationDO.getExamType().equals("16")){
			examRegistrationDO.setExamType("金砖大赛-首届老年人能力评估训练营");
		}
		examRegistrationDO.setRegistrationStartDate(DateTime.of(examRegistrationDO.getRegistrationStartDate()));
		examRegistrationDO.setRegistrationEndDate(DateTime.of(examRegistrationDO.getRegistrationEndDate()));
		examRegistrationDO.setClassMeetingDate(DateTime.of(examRegistrationDO.getClassMeetingDate()));
		examRegistrationDO.setTrainingStartDate(DateTime.of(examRegistrationDO.getTrainingStartDate()));
		examRegistrationDO.setTrainingEndDate(DateTime.of(examRegistrationDO.getTrainingEndDate()));
		examRegistrationDO.setGraduationDate(DateTime.of(examRegistrationDO.getGraduationDate()));

		List<String> trainingPdfList = new ArrayList<>();
		List<String> fileNameList = new ArrayList<>();
		List<JSONObject> list = new ArrayList<>();
		if(examRegistrationDO.getTrainingPdf() != null && examRegistrationDO.getFileName() != null){
			trainingPdfList = Arrays.asList(examRegistrationDO.getTrainingPdf().split(","));
			fileNameList = Arrays.asList(examRegistrationDO.getFileName().split(","));
			for(int i=0;i<fileNameList.size();i++){
				Map map = new HashMap();
				map.put("trainingPdf",trainingPdfList.get(i));
				map.put("fileName",fileNameList.get(i));
				JSONObject jsonObject = new JSONObject(map);
				list.add(jsonObject);
			}
		}

		model.addAttribute("list",list);
		model.addAttribute("examRegistrationDO", examRegistrationDO);
		return "certificateWeb/tradeInfo/applicationDetail";
	}
	@Log("查询考试报名相关信息")
	@ResponseBody
	@GetMapping("/listExamRegistration1")
	public Result<Page<ExamRegistrationDO>> listExamRegistration1(ExamRegistrationDO examRegistrationDO){
		Wrapper<ExamRegistrationDO> wrapper = new EntityWrapper<ExamRegistrationDO>().orderBy("id", false);
		if (StringUtil.notEmpty(examRegistrationDO.getExamType())) {
			wrapper.eq("exam_type", examRegistrationDO.getExamType());
		}
		if (StringUtil.notEmpty(examRegistrationDO.getNoticeTitle())) {
			wrapper.like("notice_title", examRegistrationDO.getNoticeTitle());
		}
		wrapper.orderBy("publish_date",false);

		// 查询列表数据
		Page<ExamRegistrationDO> page = examRegistrationService.selectPage(getPage(ExamRegistrationDO.class), wrapper);
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
			ExamRegistrationDO obj = (ExamRegistrationDO) page.getRecords().get(i);
			if (obj.getExamType().equals("0")){
				obj.setExamType("1+X幼儿照护职业技能等级证书师资及考评员");
			}
			if (obj.getExamType().equals("1")){
				obj.setExamType("1+X幼儿照护职业技能等级证书高级师资及考评员");
			}
			if (obj.getExamType().equals("2")){
				obj.setExamType("1+X幼儿照护职业技能等级证书考评员到期复审换证");
			}
			if (obj.getExamType().equals("3")){
				obj.setExamType("1+X产后恢复职业技能等级证书师资及考评员");
			}
			if (obj.getExamType().equals("4")){
				obj.setExamType("1+X幼儿照护、产后恢复职业技能等级证书考务技术与督导员");
			}
			if (obj.getExamType().equals("5")){
				obj.setExamType("高职护理——江西国培");
			}
			if (obj.getExamType().equals("6")){
				obj.setExamType("中职幼儿保育——江西国培");
			}
			if (obj.getExamType().equals("7")){
				obj.setExamType("教学能力竞赛研修班");
			}
			if (obj.getExamType().equals("8")){
				obj.setExamType("金砖大赛 - 第二届婴幼儿照护训练营");
			}
			if (obj.getExamType().equals("9")){
				obj.setExamType("金砖大赛-首届产后恢复训练营");
			}
			if (obj.getExamType().equals("10")){
				obj.setExamType("2024年国培省培班");
			}
			if (obj.getExamType().equals("11")){
				obj.setExamType("会议");
			}
			if (obj.getExamType().equals("12")){
				obj.setExamType("1+X幼儿照护、产后恢复职业技能等级证书考务技术员与督导员到期复审换证");
			}
			if (obj.getExamType().equals("13")){
				obj.setExamType("1+X产后恢复职业技能等级证书考评员到期复审换证");
			}
			if (obj.getExamType().equals("14")){
				obj.setExamType("金砖大赛-第二届产后恢复训练营");
			}
			if (obj.getExamType().equals("15")){
				obj.setExamType("金砖大赛-第三届婴幼儿照护训练营");
			}
			if (obj.getExamType().equals("16")){
				obj.setExamType("金砖大赛-首届老年人能力评估训练营");
			}

			UserDO userDO = userService.selectById(obj.getUserId());
			obj.setUserName(userService.selectById(obj.getUserId()).getUsername());
			list.add(obj);
		}
		page.setRecords(list);
		return Result.ok(page);
	}
	@Log("添加考试信息")
	@GetMapping("/addExamRegistration")
	@RequiresPermissions("jzweb:examRegistration:add")
	String addExamRegistration(){
		return "jzweb/examRegistration/addExamRegistration";
	}


	public static void main(String[] args) {
		String str = "https://jinzhiweiye.oss-cn-hangzhou.aliyuncs.com/2023/04/19/e2055371e2e04be5aec79765f2ca97ce报名管理.pdf";
		int a = str.lastIndexOf("/");
		int b = str.lastIndexOf(".");
		String substring = str.substring(a+1, b);
		char[] chars = substring.toCharArray();
		int index = 0;
		for (int i=0;i<chars.length;i++){
			char aChar = chars[i];
			String value = String.valueOf(aChar);
			if (vd(value)){
				index = i;
				break;
			}
		}
		substring = substring.substring(index);
	}



	private String getFileName(String url){
		String substring = "";
		int index = 0;
		if(!url.equals("")){
			int a = url.lastIndexOf("/");
			int b = url.lastIndexOf(".");
			substring = url.substring(a+1, b);
			char[] chars = substring.toCharArray();
			for (int i=0;i<chars.length;i++){
				char aChar = chars[i];
				String value = String.valueOf(aChar);
				if (vd(value)){
					index = i;
					break;
				}
			}
		}
		return substring.substring(index);
	}


	//判断是否为汉字
	public static boolean vd(String str) {
		String regEx = "[\u4e00-\u9fa5]";
		Pattern pat = Pattern.compile(regEx);
		Matcher matcher = pat.matcher(str);
		boolean flg = false;
		if (matcher.find())
			flg = true;
		return flg;
	}


	/**
	 *新建并保存培训报名信息
	 * @date: 2023/3/31 8:48
	 * @param: [examRegistration]
	 * @return: com.jinzhi.common.utils.Result<java.lang.String>
	 **/
	@Log("新建并保存培训报名信息")
	@ResponseBody
	@PostMapping("/saveExamRegistration")
	@RequiresPermissions("jzweb:examRegistration:add")
	public Result<String> saveExamRegistration( ExamRegistrationDO examRegistration) throws ParseException {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM
		String RegistrationStartDate = simpleDateFormat.format(examRegistration.getRegistrationStartDate());
		RegistrationStartDate = RegistrationStartDate+" 23:59:59";
		String RegistrationEndDate = simpleDateFormat.format(examRegistration.getRegistrationEndDate());
		RegistrationEndDate=RegistrationEndDate+" 23:59:59";
		String GraduationDate = simpleDateFormat.format(examRegistration.getGraduationDate());
		GraduationDate=GraduationDate+" 23:59:59";
		int result1 = new Date().compareTo(simpleDateFormat.parse(RegistrationStartDate));
		int result2 = new Date().compareTo(simpleDateFormat.parse(RegistrationEndDate));
		int result3 = new Date().compareTo(simpleDateFormat.parse(GraduationDate));

		//未开始
		if(result1 < 0){
			examRegistration.setExamStatus(0);
		}
		//报名中
		if(result1 >= 0 && result2 <= 0){
			examRegistration.setExamStatus(1);
		}
		//已截止
		if(result2 > 0){
			examRegistration.setExamStatus(3);
		}
		//已结束
		if(result3 > 0){
			examRegistration.setExamStatus(4);
		}

		examRegistration.setUserId(getUser().getId());
		examRegistration.setPublishDate(new DateTime());
		examRegistrationService.insert(examRegistration);
		return Result.ok();
	}

	@Log("进入考试报名编辑页面")
	@GetMapping("/editExamRegistration/{id}")
	@RequiresPermissions("jzweb:examRegistration:edit")
	String editExamRegistration(@PathVariable("id") Long id,Model model){
		ExamRegistrationDO examRegistrationDO = examRegistrationService.selectById(id);

//		if (examRegistrationDO.getExamType().equals("0")){
//			examRegistrationDO.setExamType("1+X幼儿照护职业技能等级证书师资及考评员");
//		}
//		if (examRegistrationDO.getExamType().equals("1")){
//			examRegistrationDO.setExamType("1+X幼儿照护职业技能等级证书高级师资及考评员");
//		}
//		if (examRegistrationDO.getExamType().equals("2")){
//			examRegistrationDO.setExamType("1+X幼儿照护职业技能等级证书考评员到期复审换证");
//		}
//		if (examRegistrationDO.getExamType().equals("3")){
//			examRegistrationDO.setExamType("1+X产后恢复职业技能等级证书师资及考评员");
//		}
//		if (examRegistrationDO.getExamType().equals("4")){
//			examRegistrationDO.setExamType("1+X幼儿照护、产后恢复职业技能等级证书考务技术与督导员");
//		}
//		if (examRegistrationDO.getExamType().equals("5")){
//			examRegistrationDO.setExamType("高职护理——江西国培");
//		}
//		if (examRegistrationDO.getExamType().equals("6")){
//			examRegistrationDO.setExamType("中职幼儿保育——江西国培");
//		}
//		if (examRegistrationDO.getExamType().equals("7")){
//			examRegistrationDO.setExamType("教学能力竞赛研修班");
//		}
//		if (examRegistrationDO.getExamType().equals("8")){
//			examRegistrationDO.setExamType("金砖大赛 - 第二届婴幼儿照护训练营");
//		}


		examRegistrationDO.setRegistrationStartDate(DateTime.of(examRegistrationDO.getRegistrationStartDate()));
		examRegistrationDO.setRegistrationEndDate(DateTime.of(examRegistrationDO.getRegistrationEndDate()));
		examRegistrationDO.setClassMeetingDate(DateTime.of(examRegistrationDO.getClassMeetingDate()));
		examRegistrationDO.setTrainingStartDate(DateTime.of(examRegistrationDO.getTrainingStartDate()));
		examRegistrationDO.setTrainingEndDate(DateTime.of(examRegistrationDO.getTrainingEndDate()));
		examRegistrationDO.setGraduationDate(DateTime.of(examRegistrationDO.getGraduationDate()));

		List<String> trainingPdfList = new ArrayList<>();
		List<String> fileNameList = new ArrayList<>();
		List<JSONObject> list = new ArrayList<>();
		if(examRegistrationDO.getTrainingPdf() != null && examRegistrationDO.getFileName() != null){
			trainingPdfList = Arrays.asList(examRegistrationDO.getTrainingPdf().split(","));
			fileNameList = Arrays.asList(examRegistrationDO.getFileName().split(","));
			for(int i=0;i<fileNameList.size();i++){
				Map map = new HashMap();
				map.put("trainingPdf",trainingPdfList.get(i));
				map.put("fileName",fileNameList.get(i));
				JSONObject jsonObject = new JSONObject(map);
				list.add(jsonObject);
			}
		}

		model.addAttribute("list",list);
		model.addAttribute("examRegistrationDO", examRegistrationDO);
		return "jzweb/examRegistration/editExamRegistration";
	}

	/**
	 *
	 * @description: 编辑并更新考试报名相关信息
	 * @author: YangQiWu
	 * @date: 2023/3/31 10:39
	 * @param: [examRegistrationDO]
	 * @return: com.jinzhi.common.utils.Result<java.lang.String>
	 **/
	@Log("编辑并更新考试报名相关信息")
	@ResponseBody
	@PostMapping("/updateExamRegistration")
	@RequiresPermissions("jzweb:examRegistration:edit")
	public Result<String> updateExamRegistration( ExamRegistrationDO examRegistrationDO) throws ParseException {
		//培训总人数不可编辑设置少于报名人数
		int registeredTrainees = examUserRegistrationService.selectCount(new EntityWrapper<ExamUserRegistrationDO>().eq("exam_registration_id", examRegistrationDO.getId()));
		if(registeredTrainees > examRegistrationDO.getTotalTrainees()){
			return Result.fail("培训总人数不可少于报名人数！");
		}
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM
		String RegistrationStartDate = simpleDateFormat.format(examRegistrationDO.getRegistrationStartDate());
		RegistrationStartDate = RegistrationStartDate+" 23:59:59";
		String RegistrationEndDate = simpleDateFormat.format(examRegistrationDO.getRegistrationEndDate());
		RegistrationEndDate=RegistrationEndDate+" 23:59:59";
		String GraduationDate = simpleDateFormat.format(examRegistrationDO.getGraduationDate());
		GraduationDate=GraduationDate+" 23:59:59";
		int result1 = new Date().compareTo(simpleDateFormat.parse(RegistrationStartDate));
		int result2 = new Date().compareTo(simpleDateFormat.parse(RegistrationEndDate));
		int result3 = new Date().compareTo(simpleDateFormat.parse(GraduationDate));
		int count = examRegistrationDO.getTotalTrainees() - examRegistrationDO.getRegisteredTrainees();
		//未开始
		if(result1 < 0){
			examRegistrationDO.setExamStatus(0);
		}
		//报名中
		if(result1>=0 && result2<=0){
			examRegistrationDO.setExamStatus(1);
		}
		//已满员
		if(count <= 0){
			examRegistrationDO.setExamStatus(2);
		}
		//已截止
		if(result2>0){
			examRegistrationDO.setExamStatus(3);
		}
		//已结束
		if(result3>0){
			examRegistrationDO.setExamStatus(4);
		}

//		List list = new ArrayList();
//		List<String> trainingPdfList = new ArrayList<>();
//		String trainingPdf = examRegistrationDO.getTrainingPdf();
//		if(trainingPdf != null){
//			trainingPdfList = Arrays.asList(trainingPdf.split(","));
//			for(int i=0;i<trainingPdfList.size();i++){
//				String name = getFileName(trainingPdfList.get(i));
//				list.add(name);
//			}
//			if(examRegistrationDO.getFileName() == null){
//				examRegistrationDO.setFileName("");
//			}
//			if(examRegistrationDO.getFileName() != null){
//				String filename = list.stream().map(String::valueOf).collect(Collectors.joining(",")).toString();
//				examRegistrationDO.setFileName(filename);
//			}
//		}else {
//			examRegistrationDO.setTrainingPdf("");
//		}

		examRegistrationDO.setUpdateDate(new DateTime());
		boolean update = examRegistrationService.updateById(examRegistrationDO);
		return update ? Result.ok() : Result.fail();
	}

	/**
	 *
	 * @description: 单个删除考试报名信息
	 * @author: YangQiWu
	 * @date: 2023/3/31 10:42
	 * @param: [id]
	 * @return: com.jinzhi.common.utils.Result<java.lang.String>
	 **/
	@Log("单个删除考试报名信息")
	@PostMapping( "/removeExamRegistration")
	@ResponseBody
	@RequiresPermissions("jzweb:examRegistration:remove")
	public Result<String> removeExamRegistration( Long id){
		boolean remove = examRegistrationService.deleteById(id);
		ExamUserRegistrationDO examUserRegistrationDO = new ExamUserRegistrationDO();
		examUserRegistrationDO.setExamRegistrationId(id);
		Wrapper<ExamUserRegistrationDO> wrapper = new EntityWrapper<ExamUserRegistrationDO>().orderBy("id", false);
		if (id != null) {
			wrapper.eq("exam_registration_id",id);
		}
		examUserRegistrationService.delete(wrapper);
		return remove ? Result.ok() : Result.fail();
	}

	/**
	 *
	 * @description: 批量删除考试报名信息
	 * @author: YangQiWu
	 * @date: 2023/3/31 10:47
	 * @param: [ids]
	 * @return: com.jinzhi.common.utils.Result<java.lang.String>
	 **/
	@Log("批量删除考试报名信息")
	@PostMapping( "/batchRemoveExamRegistration")
	@ResponseBody
	@RequiresPermissions("jzweb:examRegistration:batchRemove")
	public Result<String>  batchRemoveExamRegistration(@RequestParam("ids[]") Long[] ids){
		examRegistrationService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}

	/**
	 *
	 * @description: 培训信息详情
	 * @author: YangQiWu
	 * @date: 2023/3/31 11:01
	 * @param: [id, model]
	 * @return: java.lang.String
	 **/
	@Log("培训详情页面")
	@GetMapping("/infoExamRegistration/{id}")
	@RequiresPermissions("jzweb:examRegistration:examRegistration")
	String infoExamRegistration(@PathVariable("id") Long id, Model model) {
		ExamRegistrationDO examRegistrationDO = examRegistrationService.selectById(id);
		if (examRegistrationDO.getExamType().equals("0")){
			examRegistrationDO.setExamType("1+X幼儿照护职业技能等级证书师资及考评员");
		}
		if (examRegistrationDO.getExamType().equals("1")){
			examRegistrationDO.setExamType("1+X幼儿照护职业技能等级证书高级师资及考评员");
		}
		if (examRegistrationDO.getExamType().equals("2")){
			examRegistrationDO.setExamType("1+X幼儿照护职业技能等级证书考评员到期复审换证");
		}
		if (examRegistrationDO.getExamType().equals("3")){
			examRegistrationDO.setExamType("1+X产后恢复职业技能等级证书师资及考评员");
		}
		if (examRegistrationDO.getExamType().equals("4")){
			examRegistrationDO.setExamType("1+X幼儿照护、产后恢复职业技能等级证书考务技术与督导员");
		}
		if (examRegistrationDO.getExamType().equals("5")){
			examRegistrationDO.setExamType("高职护理——江西国培");
		}
		if (examRegistrationDO.getExamType().equals("6")){
			examRegistrationDO.setExamType("中职幼儿保育——江西国培");
		}
		if (examRegistrationDO.getExamType().equals("7")){
			examRegistrationDO.setExamType("教学能力竞赛研修班");
		}
		if (examRegistrationDO.getExamType().equals("8")){
			examRegistrationDO.setExamType("金砖大赛 - 第二届婴幼儿照护训练营");
		}
		if (examRegistrationDO.getExamType().equals("9")){
			examRegistrationDO.setExamType("金砖大赛-首届产后恢复训练营");
		}
		if (examRegistrationDO.getExamType().equals("10")){
			examRegistrationDO.setExamType("2024年国培省培班");
		}
		if (examRegistrationDO.getExamType().equals("11")){
			examRegistrationDO.setExamType("会议");
		}
		if (examRegistrationDO.getExamType().equals("12")){
			examRegistrationDO.setExamType("1+X幼儿照护、产后恢复职业技能等级证书考务技术员与督导员到期复审换证");
		}
		if (examRegistrationDO.getExamType().equals("13")){
			examRegistrationDO.setExamType("1+X产后恢复职业技能等级证书考评员到期复审换证");
		}
		if (examRegistrationDO.getExamType().equals("14")){
			examRegistrationDO.setExamType("金砖大赛-第二届产后恢复训练");
		}
		if (examRegistrationDO.getExamType().equals("15")){
			examRegistrationDO.setExamType("金砖大赛-第三届婴幼儿照护训练营");
		}
		if (examRegistrationDO.getExamType().equals("16")){
			examRegistrationDO.setExamType("金砖大赛-首届老年人能力评估训练营");
		}
		examRegistrationDO.setRegistrationStartDate(DateTime.of(examRegistrationDO.getRegistrationStartDate()));
		examRegistrationDO.setRegistrationEndDate(DateTime.of(examRegistrationDO.getRegistrationEndDate()));
		examRegistrationDO.setClassMeetingDate(DateTime.of(examRegistrationDO.getClassMeetingDate()));
		examRegistrationDO.setTrainingStartDate(DateTime.of(examRegistrationDO.getTrainingStartDate()));
		examRegistrationDO.setTrainingEndDate(DateTime.of(examRegistrationDO.getTrainingEndDate()));
		examRegistrationDO.setGraduationDate(DateTime.of(examRegistrationDO.getGraduationDate()));

		List<String> trainingPdfList = new ArrayList<>();
		List<String> fileNameList = new ArrayList<>();
		List<JSONObject> list = new ArrayList<>();
		if(examRegistrationDO.getTrainingPdf() != null && examRegistrationDO.getFileName() != null){
			trainingPdfList = Arrays.asList(examRegistrationDO.getTrainingPdf().split(","));
			fileNameList = Arrays.asList(examRegistrationDO.getFileName().split(","));
			for(int i=0;i<fileNameList.size();i++){
				Map map = new HashMap();
				map.put("trainingPdf",trainingPdfList.get(i));
				map.put("fileName",fileNameList.get(i));
				JSONObject jsonObject = new JSONObject(map);
				list.add(jsonObject);
			}
		}

		model.addAttribute("list",list);
		model.addAttribute("examRegistrationDO", examRegistrationDO);
		return "jzweb/examRegistration/infoExamRegistration";
	}

	@Log("考试报名详情信息")
	@GetMapping("/detailExamRegistration/{id}")
	@RequiresPermissions("jzweb:examRegistration:examRegistration")
	String detailExamRegistration(@PathVariable("id") Long id, Model model) {
		ExamRegistrationDO examRegistrationDO = examRegistrationService.selectById(id);
		model.addAttribute("examRegistrationDO", examRegistrationDO);
		model.addAttribute("id", id);
		model.addAttribute("examType",examRegistrationDO.getExamType());
		return "jzweb/examRegistration/detailExamRegistration";
	}

	@Log("考试报名详情信息")
	@GetMapping("/detailExamRegistration1/{id}")
	String detailExamRegistration1(@PathVariable("id") Long id, Model model) {
		ExamRegistrationDO examRegistrationDO = examRegistrationService.selectById(id);
		model.addAttribute("examRegistrationDO", examRegistrationDO);
		model.addAttribute("id", id);
		model.addAttribute("examType",examRegistrationDO.getExamType());
		return "jzweb/examRegistration/detailExamRegistration";
	}

	@Log("考试报名详情信息")
	@GetMapping("/detailExamRegistration1")
	public Result<?> detailExamRegistration1(@RequestParam("id") Long id) {
		ExamRegistrationDO examRegistrationDO = examRegistrationService.selectById(id);
		return Result.ok(examRegistrationDO);
	}

	/**
	 *
	 * @description: 查询考试报名人员相关信息
	 * @author: YangQiWu
	 * @date: 2023/3/31 10:56
	 * @param: [id]
	 * @return: com.jinzhi.common.utils.Result<com.baomidou.mybatisplus.plugins.Page<com.jinzhi.jzweb.domain.ExamUserRegistrationDO>>
	 **/
	@Log("查询考试报名人员相关信息")
	@ResponseBody
	@GetMapping("/listExamUserRegistration")
	@RequiresPermissions("jzweb:examRegistration:examRegistration")
	public Result<Page<ExamUserRegistrationDO>> listExamUserRegistration(@RequestParam("id") Long id){
		Wrapper<ExamUserRegistrationDO> wrapper = new EntityWrapper<ExamUserRegistrationDO>().orderBy("id", false);
		if (id != null) {
			wrapper.eq("exam_registration_id", id);
		}
		// 查询列表数据
		Page<ExamUserRegistrationDO> page = examUserRegistrationService.selectPage(getPage(ExamUserRegistrationDO.class), wrapper);
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
			ExamUserRegistrationDO obj = (ExamUserRegistrationDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
		return Result.ok(page);
	}

	/**
	 *
	 * @description: 考试报名人员信息详情
	 * @author: YangQiWu
	 * @date: 2023/3/31 10:56
	 * @param: [id, model]
	 * @return: java.lang.String
	 *
	<div class="form-control" th:if="${examUserRegistrationDO.politicalStatus == '1'}">群众</div>
	<div class="form-control" th:if="${examUserRegistrationDO.politicalStatus == '2'}">党员</div>
	<div class="form-control" th:if="${examUserRegistrationDO.politicalStatus == '3'}">共青团员</div>
	<div class="form-control" th:if="${examUserRegistrationDO.politicalStatus == '4'}">中共预备党员</div>
	<div class="form-control" th:if="${examUserRegistrationDO.politicalStatus == '5'}">无党派人士</div>

	<div class="form-control" th:if="${examUserRegistrationDO.positionInfo == '1'}">院长</div>
	<div class="form-control" th:if="${examUserRegistrationDO.positionInfo == '2'}">副院长</div>
	<div class="form-control" th:if="${examUserRegistrationDO.positionInfo == '3'}">主任</div>
	<div class="form-control" th:if="${examUserRegistrationDO.positionInfo == '4'}">副主任</div>
	<div class="form-control" th:if="${examUserRegistrationDO.positionInfo == '5'}">学科带头人</div>
	<div class="form-control" th:if="${examUserRegistrationDO.positionInfo == '6'}">专业负责人</div>
	<div class="form-control" th:if="${examUserRegistrationDO.positionInfo == '7'}">专业教师</div>
	<div class="form-control" th:if="${examUserRegistrationDO.positionInfo == '8'}">其他</div>
	<div class="form-control" th:if="${examUserRegistrationDO.positionInfo == '9'}">无</div>
	 **/
	@Log("考试报名人员信息详情")
	@GetMapping("/infoExamUserRegistration/{id}")
	@RequiresPermissions("jzweb:examRegistration:examRegistration")
	String infoExamUserRegistration(@PathVariable("id") Long id, Model model) {
		ExamUserRegistrationDO examUserRegistrationDO = examUserRegistrationService.selectById(id);
		if(examUserRegistrationDO.getPoliticalStatus().equals("群众")){
			examUserRegistrationDO.setPoliticalStatus("1");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("党员")){
			examUserRegistrationDO.setPoliticalStatus("2");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("共青团员")){
			examUserRegistrationDO.setPoliticalStatus("3");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("中共预备党员")){
			examUserRegistrationDO.setPoliticalStatus("4");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("无党派人士")){
			examUserRegistrationDO.setPoliticalStatus("5");
		}

		if(examUserRegistrationDO.getPositionInfo().equals("院长")){
			examUserRegistrationDO.setPositionInfo("1");
		}else if(examUserRegistrationDO.getPositionInfo().equals("副院长")){
			examUserRegistrationDO.setPositionInfo("2");
		}else if(examUserRegistrationDO.getPositionInfo().equals("主任")){
			examUserRegistrationDO.setPositionInfo("3");
		}else if(examUserRegistrationDO.getPositionInfo().equals("副主任")){
			examUserRegistrationDO.setPositionInfo("4");
		}else if(examUserRegistrationDO.getPositionInfo().equals("学科带头人")){
			examUserRegistrationDO.setPositionInfo("5");
		}else if(examUserRegistrationDO.getPositionInfo().equals("专业负责人")){
			examUserRegistrationDO.setPositionInfo("6");
		}else if(examUserRegistrationDO.getPositionInfo().equals("专业教师")){
			examUserRegistrationDO.setPositionInfo("7");
		}else if(examUserRegistrationDO.getPositionInfo().equals("其他")){
			examUserRegistrationDO.setPositionInfo("8");
		}else if(examUserRegistrationDO.getPositionInfo().equals("无")){
			examUserRegistrationDO.setPositionInfo("9");
		}
		if(examUserRegistrationDO.getTitleInfo().equals("教授")){
			examUserRegistrationDO.setTitleInfo("1");
		}else if(examUserRegistrationDO.getTitleInfo().equals("副教授")){
			examUserRegistrationDO.setTitleInfo("2");
		}else if(examUserRegistrationDO.getTitleInfo().equals("讲师")){
			examUserRegistrationDO.setTitleInfo("3");
		}else if(examUserRegistrationDO.getTitleInfo().equals("助教")){
			examUserRegistrationDO.setTitleInfo("4");
		}else if(examUserRegistrationDO.getTitleInfo().equals("无")){
			examUserRegistrationDO.setTitleInfo("5");
		}

		model.addAttribute("examUserRegistrationDO", examUserRegistrationDO);
		model.addAttribute("id",id);
		model.addAttribute("examRegistrationId",examUserRegistrationDO.getExamRegistrationId());
		return "jzweb/examRegistration/infoExamUserRegistration";
	}

	@Log("进入考试报名人员编辑页面")
	@GetMapping("/editExamUserRegistration/{id}")
	@RequiresPermissions("jzweb:examRegistration:edit")
	String editExamUserRegistration(@PathVariable("id") Long id,Model model){
		ExamUserRegistrationDO examUserRegistrationDO = examUserRegistrationService.selectById(id);
		//政治面貌处理
		if(examUserRegistrationDO.getPoliticalStatus().equals("群众")){
			examUserRegistrationDO.setPoliticalStatus("1");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("党员")){
			examUserRegistrationDO.setPoliticalStatus("2");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("共青团员")){
			examUserRegistrationDO.setPoliticalStatus("3");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("中共预备党员")){
			examUserRegistrationDO.setPoliticalStatus("4");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("无党派人士")){
			examUserRegistrationDO.setPoliticalStatus("5");
		}
		//职位处理
		if(examUserRegistrationDO.getPositionInfo().equals("院长")){
			examUserRegistrationDO.setPositionInfo("1");
		}else if(examUserRegistrationDO.getPositionInfo().equals("副院长")){
			examUserRegistrationDO.setPositionInfo("2");
		}else if(examUserRegistrationDO.getPositionInfo().equals("主任")){
			examUserRegistrationDO.setPositionInfo("3");
		}else if(examUserRegistrationDO.getPositionInfo().equals("副主任")){
			examUserRegistrationDO.setPositionInfo("4");
		}else if(examUserRegistrationDO.getPositionInfo().equals("学科带头人")){
			examUserRegistrationDO.setPositionInfo("5");
		}else if(examUserRegistrationDO.getPositionInfo().equals("专业负责人")){
			examUserRegistrationDO.setPositionInfo("6");
		}else if(examUserRegistrationDO.getPositionInfo().equals("专业教师")){
			examUserRegistrationDO.setPositionInfo("7");
		}else if(examUserRegistrationDO.getPositionInfo().equals("其他")){
			examUserRegistrationDO.setPositionInfo("8");
		}else if(examUserRegistrationDO.getPositionInfo().equals("无")){
			examUserRegistrationDO.setPositionInfo("9");
		}
		//职称处理
		if(examUserRegistrationDO.getTitleInfo().equals("教授")){
			examUserRegistrationDO.setTitleInfo("1");
		}else if(examUserRegistrationDO.getTitleInfo().equals("副教授")){
			examUserRegistrationDO.setTitleInfo("2");
		}else if(examUserRegistrationDO.getTitleInfo().equals("讲师")){
			examUserRegistrationDO.setTitleInfo("3");
		}else if(examUserRegistrationDO.getTitleInfo().equals("助教")){
			examUserRegistrationDO.setTitleInfo("4");
		}else if(examUserRegistrationDO.getTitleInfo().equals("无")){
			examUserRegistrationDO.setTitleInfo("5");
		}
		model.addAttribute("examUserRegistrationDO", examUserRegistrationDO);
		return "jzweb/examRegistration/editExamUserRegistration";
	}

	/**
	 *
	 * @description: 编辑并更新考试报名人员相关信息
	 * @author: YangQiWu
	 * @date: 2023/3/30 18:19
	 * @param: [examRegistration]
	 * @return: com.jinzhi.common.utils.Result<java.lang.String>
	 **/
	@Log("编辑并更新考试报名人员相关信息")
	@ResponseBody
	@PostMapping("/updateExamUserRegistration")
	@RequiresPermissions("jzweb:examRegistration:edit")
	public Result<String> updateExamUserRegistration( ExamUserRegistrationDO examUserRegistrationDO){
		//政治面貌处理
		if(examUserRegistrationDO.getPoliticalStatus().equals("1")){
			examUserRegistrationDO.setPoliticalStatus("群众");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("2")){
			examUserRegistrationDO.setPoliticalStatus("党员");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("3")){
			examUserRegistrationDO.setPoliticalStatus("共青团员");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("4")){
			examUserRegistrationDO.setPoliticalStatus("中共预备党员");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("5")){
			examUserRegistrationDO.setPoliticalStatus("无党派人士");
		}
		//职位处理
		if(examUserRegistrationDO.getPositionInfo().equals("1")){
			examUserRegistrationDO.setPositionInfo("院长");
		}else if(examUserRegistrationDO.getPositionInfo().equals("2")){
			examUserRegistrationDO.setPositionInfo("副院长");
		}else if(examUserRegistrationDO.getPositionInfo().equals("3")){
			examUserRegistrationDO.setPositionInfo("主任");
		}else if(examUserRegistrationDO.getPositionInfo().equals("4")){
			examUserRegistrationDO.setPositionInfo("副主任");
		}else if(examUserRegistrationDO.getPositionInfo().equals("5")){
			examUserRegistrationDO.setPositionInfo("学科带头人");
		}else if(examUserRegistrationDO.getPositionInfo().equals("6")){
			examUserRegistrationDO.setPositionInfo("专业负责人");
		}else if(examUserRegistrationDO.getPositionInfo().equals("7")){
			examUserRegistrationDO.setPositionInfo("专业教师");
		}else if(examUserRegistrationDO.getPositionInfo().equals("8")){
			examUserRegistrationDO.setPositionInfo("其他");
		}else if(examUserRegistrationDO.getPositionInfo().equals("9")){
			examUserRegistrationDO.setPositionInfo("无");
		}
		//职称处理
		if(examUserRegistrationDO.getTitleInfo().equals("1")){
			examUserRegistrationDO.setTitleInfo("教授");
		}else if(examUserRegistrationDO.getTitleInfo().equals("2")){
			examUserRegistrationDO.setTitleInfo("副教授");
		}else if(examUserRegistrationDO.getTitleInfo().equals("3")){
			examUserRegistrationDO.setTitleInfo("讲师");
		}else if(examUserRegistrationDO.getTitleInfo().equals("4")){
			examUserRegistrationDO.setTitleInfo("助教");
		}else if(examUserRegistrationDO.getTitleInfo().equals("5")){
			examUserRegistrationDO.setTitleInfo("无");
		}
		boolean update = examUserRegistrationService.updateById(examUserRegistrationDO);
		return update ? Result.ok() : Result.fail();
	}

	@Log("进入考试人员信息添加页面")
	@GetMapping("/addExamUserRegistration/{id}")
	@RequiresPermissions("jzweb:examRegistration:add")
	String addExamUserRegistration(@PathVariable("id") Long examRegistrationId,Model model){
		model.addAttribute("examRegistrationId",examRegistrationId);
		return "jzweb/examRegistration/addExamUserRegistration";
	}

	/**
	 *
	 * @description: 添加并保存考试人员信息
	 * @author: YangQiWu
	 * @date: 2023/3/31 9:11
	 * @param: [examUserRegistrationDO]
	 * @return: com.jinzhi.common.utils.Result<java.lang.String>
	 **/
	@Log("添加并保存培训人员信息")
	@ResponseBody
	@PostMapping("/saveExamUserRegistration")
	@RequiresPermissions("jzweb:examRegistration:add")
	public Result<String> saveExamUserRegistration( ExamUserRegistrationDO examUserRegistrationDO){
		//判断是否满员
		int totalTrainees = examRegistrationService.selectById(examUserRegistrationDO.getExamRegistrationId()).getTotalTrainees();
		int registeredTrainees = examUserRegistrationService.selectCount(new EntityWrapper<ExamUserRegistrationDO>().eq("exam_registration_id", examUserRegistrationDO.getExamRegistrationId()));
		if(registeredTrainees >= totalTrainees){
			return Result.fail("报名人数已满员！");
		}
		//政治面貌处理
		if(examUserRegistrationDO.getPoliticalStatus().equals("1")){
			examUserRegistrationDO.setPoliticalStatus("群众");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("2")){
			examUserRegistrationDO.setPoliticalStatus("党员");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("3")){
			examUserRegistrationDO.setPoliticalStatus("共青团员");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("4")){
			examUserRegistrationDO.setPoliticalStatus("中共预备党员");
		}else if(examUserRegistrationDO.getPoliticalStatus().equals("5")){
			examUserRegistrationDO.setPoliticalStatus("无党派人士");
		}
		//职位处理
		if(examUserRegistrationDO.getPositionInfo().equals("1")){
			examUserRegistrationDO.setPositionInfo("院长");
		}else if(examUserRegistrationDO.getPositionInfo().equals("2")){
			examUserRegistrationDO.setPositionInfo("副院长");
		}else if(examUserRegistrationDO.getPositionInfo().equals("3")){
			examUserRegistrationDO.setPositionInfo("主任");
		}else if(examUserRegistrationDO.getPositionInfo().equals("4")){
			examUserRegistrationDO.setPositionInfo("副主任");
		}else if(examUserRegistrationDO.getPositionInfo().equals("5")){
			examUserRegistrationDO.setPositionInfo("学科带头人");
		}else if(examUserRegistrationDO.getPositionInfo().equals("6")){
			examUserRegistrationDO.setPositionInfo("专业负责人");
		}else if(examUserRegistrationDO.getPositionInfo().equals("7")){
			examUserRegistrationDO.setPositionInfo("专业教师");
		}else if(examUserRegistrationDO.getPositionInfo().equals("8")){
			examUserRegistrationDO.setPositionInfo("其他");
		}else if(examUserRegistrationDO.getPositionInfo().equals("9")){
			examUserRegistrationDO.setPositionInfo("无");
		}
		//职称处理
		if(examUserRegistrationDO.getTitleInfo().equals("1")){
			examUserRegistrationDO.setTitleInfo("教授");
		}else if(examUserRegistrationDO.getTitleInfo().equals("2")){
			examUserRegistrationDO.setTitleInfo("副教授");
		}else if(examUserRegistrationDO.getTitleInfo().equals("3")){
			examUserRegistrationDO.setTitleInfo("讲师");
		}else if(examUserRegistrationDO.getTitleInfo().equals("4")){
			examUserRegistrationDO.setTitleInfo("助教");
		}else if(examUserRegistrationDO.getTitleInfo().equals("5")){
			examUserRegistrationDO.setTitleInfo("无");
		}
		examUserRegistrationDO.setRegistrationTime(new DateTime());
		examUserRegistrationService.insert(examUserRegistrationDO);
		int count = examUserRegistrationService.selectCount(new EntityWrapper<ExamUserRegistrationDO>().eq("exam_registration_id", examUserRegistrationDO.getExamRegistrationId()));
		ExamRegistrationDO examRegistrationDO = new ExamRegistrationDO();
		examRegistrationDO.setId(examUserRegistrationDO.getExamRegistrationId());
		examRegistrationDO.setRegisteredTrainees(count);
		if(count == totalTrainees){
			examRegistrationDO.setExamStatus(2);
		}
		examRegistrationService.updateById(examRegistrationDO);
		return Result.ok();
	}

	/**
	 *
	 * @description: 单个删除考试报名人员信息
	 * @author: YangQiWu
	 * @date: 2023/3/30 18:26
	 * @param: [id]
	 * @return: com.jinzhi.common.utils.Result<java.lang.String>
	 **/
	@Log("单个删除考试报名人员信息")
	@PostMapping( "/removeExamUserRegistration")
	@ResponseBody
	@RequiresPermissions("jzweb:examRegistration:remove")
	public Result<String>  removeExamUserRegistration( Long id){
		ExamUserRegistrationDO 	examUserRegistrationDO = examUserRegistrationService.selectById(id);
		boolean update= false;
		ExamRegistrationDO examRegistrationDO = examRegistrationService.selectById(examUserRegistrationDO.getExamRegistrationId());

		if(examRegistrationDO.getExamStatus()==3||examRegistrationDO.getExamStatus()==4){
			return Result.fail("该状态不能进行删除！");
		}

		boolean remove = examUserRegistrationService.deleteById(id);
		if(remove){
//			ExamUserRegistrationDO examUserRegistrationDO = new ExamUserRegistrationDO();
//			examUserRegistrationDO.setId(id);


			int count = examUserRegistrationService.selectCount(new EntityWrapper<ExamUserRegistrationDO>().eq("exam_registration_id", examUserRegistrationDO.getExamRegistrationId()));


			examRegistrationDO.setRegisteredTrainees(count);

			if(examRegistrationDO.getExamStatus()==2){
				if(examRegistrationDO.getTotalTrainees()>count){
					examRegistrationDO.setExamStatus(1);
				}
			}

			update=	examRegistrationService.updateById(examRegistrationDO);
		}

		return update ? Result.ok() : Result.fail("删除失败,请联系管理人员！");
	}

	/**
	 *
	 * @description: 批量删除考试报名人员信息
	 * @author: YangQiWu
	 * @date: 2023/3/30 18:27
	 * @param: [ids]
	 * @return: com.jinzhi.common.utils.Result<java.lang.String>
	 **/
	@Log("批量删除")
	@PostMapping( "/batchRemoveExamUserRegistration")
	@ResponseBody
	@RequiresPermissions("jzweb:examRegistration:batchRemove")
	public Result<String>  batchRemoveExamUserRegistration(@RequestParam("ids[]") Long[] ids){
		examUserRegistrationService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}

	/**
	 *
	 * @description: 导出报名信息
	 * @author: YangQiWu
	 * @date: 2023/3/31 17:07
	 * @param: [request, response]
	 * @return: void
	 **/
	@Log("导出报名信息")
	@GetMapping("/exportExamUserRegistration")
	@ResponseBody
	@RequiresPermissions("jzweb:examRegistration:export")
	public void exportExamUserRegistration(HttpServletRequest request, HttpServletResponse response,Long examId,String[] rows) throws Exception {
		Wrapper<ExamUserRegistrationDO> wrapper = new EntityWrapper<ExamUserRegistrationDO>().orderBy("id", false);
		List<ExamUserRegistrationDO> groupList = new ArrayList<>();
		if (examId != null) {
			wrapper.eq("exam_registration_id",examId);
			groupList = examUserRegistrationService.selectList(wrapper);
		}
		if(rows.length > 0) {
			groupList =	examUserRegistrationService.selectBatchIds(Arrays.asList(rows));
			groupList = groupList.stream().sorted(Comparator.comparing(ExamUserRegistrationDO::getId).reversed()).collect(Collectors.toList());
		}
		int seq = 1;
		List<ExamUserRegistrationExportVo> excelList = new ArrayList<ExamUserRegistrationExportVo>();
		for(ExamUserRegistrationDO info : groupList) {
			ExamUserRegistrationExportVo excel = new ExamUserRegistrationExportVo();

			excel.setStuName(info.getName());//姓名

			if(info.getGender() == null){
				excel.setSex("");
			}else if(info.getGender() == 2){
				excel.setSex("女");
			}else if(info.getGender() == 1){
				excel.setSex("男");
			}

			excel.setStuMobile(info.getContact());




			if(info.getPoliticalStatus().equals("1")){
				excel.setPoliticsStatus("群众");
			}else if(info.getPoliticalStatus().equals("2")){
				excel.setPoliticsStatus("党员");
			}else if(info.getPoliticalStatus().equals("3")){
				excel.setPoliticsStatus("共青团员");
			}else if(info.getPoliticalStatus().equals("4")){
				excel.setPoliticsStatus("中共预备党员");
			}else if(info.getPoliticalStatus().equals("5")){
				excel.setPoliticsStatus("无党派人士");
			}else {
				excel.setPoliticsStatus(info.getPoliticalStatus());
			}

			if (info.getType().equals("0")){
				excel.setType("1+X幼儿照护职业技能等级证书师资及考评员");
			}
			if (info.getType().equals("1")){
				excel.setType("1+X幼儿照护职业技能等级证书高级师资及考评员");
			}
			if (info.getType().equals("2")){
				excel.setType("1+X幼儿照护职业技能等级证书考评员到期复审换证");
			}
			if (info.getType().equals("3")){
				excel.setType("1+X产后恢复职业技能等级证书师资及考评员");
			}
			if (info.getType().equals("4")){
				excel.setType("1+X幼儿照护、产后恢复职业技能等级证书考务技术与督导员");
			}
			if (info.getType().equals("5")){
				excel.setType("高职护理——江西国培");
			}
			if (info.getType().equals("6")){
				excel.setType("中职幼儿保育——江西国培");
			}
			if (info.getType().equals("7")){
				excel.setType("教学能力竞赛研修班");
			}
			if (info.getType().equals("8")){
				excel.setType("金砖大赛 - 第二届婴幼儿照护训练营");
			}
			if (info.getType().equals("9")){
				excel.setType("金砖大赛-首届产后恢复训练营");
			}
			if (info.getType().equals("10")){
				excel.setType("2024年国培省培班");
			}
			if (info.getType().equals("11")){
				excel.setType("会议");
			}
			if (info.getType().equals("12")){
				excel.setType("1+X幼儿照护、产后恢复职业技能等级证书考务技术员与督导员到期复审换证");
			}
			if (info.getType().equals("13")){
				excel.setType("1+X产后恢复职业技能等级证书考评员到期复审换证");
			}
			if (info.getType().equals("14")){
				excel.setType("金砖大赛-第二届产后恢复训练营");
			}
			if (info.getType().equals("15")){
				excel.setType("金砖大赛-第三届婴幼儿照护训练营");
			}
			if (info.getType().equals("16")){
				excel.setType("金砖大赛-首届老年人能力评估训练营");
			}
			excel.setCertificationType(info.getCertificationType());
//			excel.setCertificateUrl(info.getCertificateUrl());
			excel.setSchoolName(info.getSchoolName());
			excel.setSchoolRecommend(info.getSchoolRecommend());

			excel.setUserProvince(info.getProvince());
			excel.setIdCard(info.getIdCardNumber());
			excel.setEmail(info.getEmail());
			excel.setWorkUnit(info.getCompanyName());
			excel.setAddresses(info.getMailingAddress() + "/" +info.getDetailedMailingAddress());
			if (excel.getTaxNumber()!=null){
				excel.setTaxNumber(info.getTaxNumber()); //税号
			}else {
				excel.setTaxNumber(""); //税号
			}
			if(info.getDepartment() == null){
				excel.setSpecialty(""+" "+info.getMajor());
			}else {
				excel.setSpecialty(info.getDepartment()+" "+info.getMajor());
			}
			if(info.getPositionInfo().equals("1")){
				excel.setPosition("院长");
			}else if(info.getPositionInfo().equals("2")){
				excel.setPosition("副院长");
			}else if(info.getPositionInfo().equals("3")){
				excel.setPosition("主任");
			}else if(info.getPositionInfo().equals("4")){
				excel.setPosition("副主任");
			}else if(info.getPositionInfo().equals("5")){
				excel.setPosition("学科带头人");
			}else if(info.getPositionInfo().equals("6")){
				excel.setPosition("专业负责人");
			}else if(info.getPositionInfo().equals("7")){
				excel.setPosition("专业教师");
			}else if(info.getPositionInfo().equals("8")){
				excel.setPosition("其他");
			}else if(info.getPositionInfo().equals("9")){
				excel.setPosition("无");
			}else{
				excel.setPosition(info.getPositionInfo());
			}

			if(info.getTitleInfo() == null){
				excel.setPositionName("");
			}else if(info.getTitleInfo().equals("1")){
				excel.setPositionName("教授");
			}else if(info.getTitleInfo().equals("2")){
				excel.setPositionName("副教授");
			}else if(info.getTitleInfo().equals("3")){
				excel.setPositionName("讲师");
			}else if(info.getTitleInfo().equals("4")){
				excel.setPositionName("助教");
			}else if(info.getTitleInfo().equals("5")){
				excel.setPositionName("无");
			}else {
				excel.setPositionName(info.getTitleInfo());
			}
			if(StringUtil.notEmpty(info.getPhotoInfo())){
				excel.setImageUrl(info.getPhotoInfo());
			}
			excelList.add(excel);
		}
		EasyPoiUtil.exportExcel(excelList, "考试报名信息", "考试报名信息", ExamUserRegistrationExportVo.class, "考试报名信息表", response);
	}

}
